package com.yjd.bi.canal.util;

import java.util.List;

import com.sun.tools.javac.code.Attribute.Array;
import com.yjd.bi.canal.model.CanalListenedTableModel;
import com.yjd.bi.canal.service.ICanalMessageService;
import com.yjd.bi.report.model.BiTableInfoModel;
import com.yjd.bi.report.service.IBiTableInfoService;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.rpm.RpmServiceKeyEnum;
import com.yjd.comm.util.FrameUtil;
import com.yjd.comm.util.ServiceHolder;

public class CanalListenedTableUtil {
	private static List<CanalListenedTableModel> tables;
	
	public static List<CanalListenedTableModel> getTables() throws Exception{
		if(tables==null){
			refresh();
		}
		return tables;
	}
	
	protected static void refresh() throws Exception{
		tables=FrameUtil.newArrayList();
		ICanalMessageService canalMessageService=ServiceHolder.getService(ICanalMessageService.class, "canalMessageService", RpmServiceKeyEnum.RPM_BI_SERVICE_KEY_E);
		tables=canalMessageService.getTableList(DbWREnums.READ);
	}
	
	/**
	 * 返回是否在监听列表中
	 * @param table
	 * @param schema
	 * @return
	 * @throws Exception
	 */
	public static boolean isInListened(String table,String schema) throws Exception{
		for(CanalListenedTableModel t:getTables()){
			if(t.getSchema().equals(schema)&&t.getTable().equals(table)){
				return true;
			}
		}
		return false;
	}
}
